package com.zyong.design.pattern.memento.case2;

import java.util.Stack;

/**
 * @program: zyong-design-pattern
 * @ClassName: Caretaker
 * @author: zyong
 * @create: 2024-05-12 23:01
 */
public class Caretaker {
    private final Stack<Memento> savedStates = new Stack<Memento>();

    public void addMemento(Memento memento) {
        savedStates.push(memento);
    }

    public Memento getMemento() {
        return savedStates.pop();
    }

    /**
     * 检查是否有保存的状态可供恢复
     * @return
     */
    public boolean hasSavedStates() {
        return !savedStates.isEmpty();
    }
}
